<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      Object.myCreate = function (proto, propertiesObject = undefined) {
        if (typeof proto !== 'object' && proto !== null && typeof proto !== 'function') {
          throw new Error('Uncaught TypeError: Object prototype may only be an Object or null');
        }
        function F() {}
        F.prototype = proto;
        let obj = new F();
        if (propertiesObject !== undefined) {
          Object.defineProperties(obj, propertiesObject);
        }
        return obj;
      };
      let obj = {
        name: 'zs',
        age: 18,
      };
      let newObj = Object.myCreate(obj, {
        hobby: {
          // 初始化值
          value: true,
          // 是否可修改
          writable: true,
          // 是否能被删除
          configurable: true,
          // 是否可以用 for in 遍历枚举
          enumerable: true,
        },
        name: {
          value: 'zs',
        },
      });
      console.log(newObj);
      console.log(newObj.__proto__ == obj); // true
    </script>
  </body>
</html>
